package com.ruoyi.service.reward.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.service.reward.entity.LaborRewardEntity;
import com.ruoyi.service.reward.mapper.LaborRewardMapper;
import com.ruoyi.service.reward.query.RewardQuery;
import com.ruoyi.service.reward.service.LaborRewardService;
import java.util.List;
import java.util.Objects;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 员工奖惩记录 服务实现类
 * </p>
 *
 * @author Zane
 * @since 2025-10-26
 */
@Service
public class LaborRewardServiceImpl extends ServiceImpl<LaborRewardMapper, LaborRewardEntity>
    implements LaborRewardService {

  @Override
  public List<LaborRewardEntity> listRewardLabor(RewardQuery query, Long laborId) {
    return list(queryWrapper().eq(LaborRewardEntity::getLaborId, laborId)
        .orderByDesc(LaborRewardEntity::getId));
  }

  @Override
  public List<LaborRewardEntity> listReward(RewardQuery query) {
    final LambdaQueryWrapper<LaborRewardEntity> queryWrapper = queryWrapper().orderByDesc(
        LaborRewardEntity::getId);
    if (Objects.nonNull(query.getUserId())) {
      queryWrapper.eq(LaborRewardEntity::getLaborId, query.getUserId());
    }
    return list(queryWrapper);
  }

  @Override
  public Long getRewardCount(Long userId) {
    return count(queryWrapper().eq(LaborRewardEntity::getLaborId, userId));
  }

  private LambdaQueryWrapper<LaborRewardEntity> queryWrapper() {
    return new LambdaQueryWrapper<>();
  }
}
